/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.appstreet.dao.impl;

import com.opgea.appstreet.dao.SubCategoryDAO;
import com.opgea.appstreet.domain.entities.SubCategory;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Ramesh
 */
@Repository
public class SubCategoryDAOImpl implements SubCategoryDAO{

    @Autowired
    private SessionFactory sessionFactory;
    
    @Override
    public SubCategory create(SubCategory subCategory) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public SubCategory update(SubCategory subCategory) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public SubCategory find(Long id) {
        Session session = sessionFactory.openSession();
        Query query = session.getNamedQuery("SubCategory.findById");
        query.setParameter("id", id);
        return (SubCategory) query.uniqueResult();
    }

    @Override
    public List<SubCategory> findAll() {
        Session session = sessionFactory.openSession();
        Query query = session.getNamedQuery("SubCategory.findAll");
        return query.list();
    }

    @Override
    public List<SubCategory> findByCategory(Long id) {
        Session session = sessionFactory.openSession();
        Query query = session.getNamedQuery("SubCategory.findByCategoryId");
        query.setParameter("id", id);
        return query.list();
    }
    
}
